package server

import (
	"gorm_demo/pkg/http/rest"
	"gorm_demo/pkg/service"

	"github.com/gin-gonic/gin"
)

func (ds *dserver) MapRoutes() {

	// Group : v1
	apiV1 := ds.router.Group("api/v1")

	// ds.healthRoutes(apiV1)
	// ds.loginRoutes(apiV1)
	ds.userRoutes(apiV1)
}

// func (ds *dserver) healthRoutes(api *gin.RouterGroup) {
// 	healthRoutes := api.Group("/health")
// 	{
// 		h := rest.NewHealthCtrl()
// 		healthRoutes.GET("/", h.Ping)
// 	}
// }

// func (ds *dserver) loginRoutes(api *gin.RouterGroup) {
// 	var loginSvc login.Service
// 	ds.cont.Invoke(func(l login.Service) {
// 		loginSvc = l
// 	})

// 	loginRoutes := api.Group("/login")
// 	{
// 		f := rest.NewLoginCtrl(ds.logger, loginSvc)
// 		loginRoutes.POST("/", f.Signin)
// 	}
// }

func (ds *dserver) userRoutes(api *gin.RouterGroup) {
	userRoutes := api.Group("/users")
	{
		var userSvc service.AuthUserService
		ds.cont.Invoke(func(u service.AuthUserService) {
			userSvc = u
		})

		usr := rest.NewUserCtrl(ds.logger, userSvc)

		userRoutes.GET("/", usr.List)
		userRoutes.POST("/", usr.Create)
		userRoutes.GET("/:id", usr.GetById)
		userRoutes.PUT("/:id", usr.Update)
		userRoutes.DELETE("/:id", usr.Delete)
	}
}
